package com.ruoyi.classai.controller;

import java.util.Arrays;
import java.util.List;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.classai.domain.EwcAttendanceRecords;
import com.ruoyi.classai.service.IEwcAttendanceRecordsService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 考勤记录Controller
 * 
 * @author lcj
 * @date 2025-02-28
 */
@RestController
@RequestMapping("/records")
public class EwcAttendanceRecordsController extends BaseController
{
    @Autowired
    private IEwcAttendanceRecordsService ewcAttendanceRecordsService;

    /**
     * 查询考勤记录列表
     */
    @RequiresPermissions("classai:records:list")
    @GetMapping("/list")
    public TableDataInfo list(EwcAttendanceRecords ewcAttendanceRecords)
    {
        startPage();
        List<EwcAttendanceRecords> list = ewcAttendanceRecordsService.list(Wrappers.query(ewcAttendanceRecords));
        return getDataTable(list);
    }

    /**
     * 导出考勤记录列表
     */
    @RequiresPermissions("classai:records:export")
    @Log(title = "考勤记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EwcAttendanceRecords ewcAttendanceRecords)
    {
        List<EwcAttendanceRecords> list = ewcAttendanceRecordsService.list(Wrappers.query(ewcAttendanceRecords));
        ExcelUtil<EwcAttendanceRecords> util = new ExcelUtil<EwcAttendanceRecords>(EwcAttendanceRecords.class);
        util.exportExcel(response, list, "考勤记录数据");
    }

    /**
     * 获取考勤记录详细信息
     */
    @RequiresPermissions("classai:records:query")
    @GetMapping(value = "/getInfo/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ewcAttendanceRecordsService.getById(id));
    }

    /**
     * 新增考勤记录
     */
    @RequiresPermissions("classai:records:add")
    @Log(title = "考勤记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody EwcAttendanceRecords ewcAttendanceRecords)
    {
        return toAjax(ewcAttendanceRecordsService.save(ewcAttendanceRecords));
    }

    /**
     * 修改考勤记录
     */
    @RequiresPermissions("classai:records:edit")
    @Log(title = "考勤记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody EwcAttendanceRecords ewcAttendanceRecords)
    {
        return toAjax(ewcAttendanceRecordsService.updateById(ewcAttendanceRecords));
    }

    /**
     * 删除考勤记录
     */
    @RequiresPermissions("classai:records:remove")
    @Log(title = "考勤记录", businessType = BusinessType.DELETE)
	@GetMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ewcAttendanceRecordsService.removeByIds(Arrays.asList(ids)));
    }
}
